﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace XjjXmm.CodeGenerator.FileStangy
{
    interface IFileGeneratorStrangy
    {
        dynamic Generator(string file);
    }

    class DasFileGeneratorStrangy : IFileGeneratorStrangy
    {
        public dynamic Generator(string file)
        {
            var sb = new StringBuilder();
                
           var strs = File.ReadAllLines(file);

            var package = "";
            var clazz = "";
            var fileds = new List<dynamic>();
            
            foreach (string str in strs)
            {
                var line = str.Trim();

                var match = Regex.Match(line, "package.*?(com.*?);.*?");
                if (match.Success)
                {
                    package = match.Groups[1].Value;

                }

                match = Regex.Match(line, "public.*?class\\s(.*?)\\s.*?{");
                if(match.Success)
                {
                    clazz = match.Groups[1].Value.Trim();
                }

                match = Regex.Match(line, "^private.*?String(.*?);");
                if (match.Success)
                {
                    var field = match.Groups[1].Value.Trim();
                    fileds.Add(new
                    {
                        lower = ConverLowName(field),
                        upper = ConverUpperName(field)
                    });
                }
            }

            return new
            {
                package = package,
                clazz = clazz,
                fileds = fileds
            };

        }

        protected string ConverLowName(string field)
        {
            var res = "";
            
            res += field.Substring(0, 1).ToLower() + field.Substring(1);

            return res;
        }

        protected string ConverUpperName(string field)
        {
            var res = "";

            res += field.Substring(0, 1).ToUpper() + field.Substring(1);

            return res;
        }
    }



}
